<template>
  <div>
    <el-form
      ref="form"
      :model="usersParameter"
      label-width="100px"
      :rules="addFromRules"
    >
      <el-form-item label="用户名" prop="username">
        <el-input v-model="usersParameter.username"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="usersParameter.email"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="usersParameter.password"></el-input>
      </el-form-item>
      <el-form-item label="角色">
        <el-input v-model="usersParameter.role"></el-input>
      </el-form-item>
      <el-form-item label="权限组名称">
        <el-select
          v-model="usersParameter.permission_group_id"
          placeholder="请选择"
        >
          <el-option
            v-for="item in options"
            :key="item.id"
            :label="item.title"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input v-model="usersParameter.phone"></el-input>
      </el-form-item>
      <el-form-item label="介绍">
        <el-input
          type="textarea"
          v-model="usersParameter.introduction"
        ></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { detail, update, add } from '@/api/base/users'  //eslint-disable-line
export default {
  props: {
    options: {
      type: Array,
      required: true
    }
  },
  data () {
    // 邮箱校验规则
    const checkEmail = function (rule, value, cb) {
      const reg = /^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*\.[a-z]{2,}$/
      if (reg.test(value)) {
        cb()
      } else {
        cb(new Error('邮箱格式不对'))
      }
    }
    // 手机号校验规则
    const checkMobile = function (rule, value, cb) {
      const reg = /^(0|86|17951)?(13[0-9]|15[012356789]|16[6]|19[89]]|17[01345678]|18[0-9]|14[579])[0-9]{8}$/
      if (reg.test(value)) {
        cb()
      } else {
        cb(new Error('手机格式不对'))
      }
    }
    return {
      dialogFormVisible: true
      // fileList: [],
      // importFileUrl: 'https://jsonplaceholder.typicode.com/posts/',
    }
  },
  updated () {
    this.toUsers()
  },
  methods: {
    toUsers () {
      this.$emit('onUsersParameter', this.usersParameter)
    }
  }
}
</script>

<style>
.el-form--label-left .el-form-item__label {
  text-align: right;
}

.el-form-item--medium {
  margin-bottom: 22px;
}

.el-dialog__footer {
  text-align: center;
}
</style>
